<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>本地永久存储</title>
</head>
<body>
    <!-- window.localStorage 
                       生命周期永久有效 除非手动删除否则关闭页面也会存在
                       可以多窗口共享 （同一浏览器可以共享）
                       一键值对的形式存储使用 -->


                       <input type="text">
                       <button class="set">存储数据</button>
                       <button class="get">获取数据</button>
                       <button class="remove">删除数据</button>
                       <button class="del">清空所有数据</button>
                           <script>
                           
                           var  ipt = document.querySelector('input');
                           var  set = document.querySelector('.set');
                   
                           var get = document.querySelector('.get');
                   
                           var remove = document.querySelector('.remove');
                           var del = document.querySelector('.del');

                           set.addEventListener('click',function() {
                               var val = ipt.value;
                               localStorage.setItem('username',val)
                           })

                           get.addEventListener('click',function() {
                               
                               console.log(localStorage.getItem('username'));
                           })


                           remove.addEventListener('click',function() {
                               
                               localStorage.removeItem('username');
                           })

                           del.addEventListener('click',function() {
                               
                               localStorage.clear();
                           })
                           </script>
</body>
</html>